﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.ServiceModel.DomainServices.Client;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Arch.Samples.RiaServices.Infrastructure;

namespace Arch.Samples.RiaServices.Commands
{
    public class SubmitCollectionCommand<TViewModel, TEntity> : CollectionViewModelCommand<TViewModel, TEntity> 
        where TViewModel : CollectionViewModelBase<TEntity>
        where TEntity : Entity
    {
        public SubmitCollectionCommand(TViewModel viewModel) : base(viewModel) { }

        public override bool CanExecute(object parameter)
        {
            return !ViewModel.Items.Any(i => i.ValidationErrors.Any());
        }

        public override void Execute(object parameter)
        {
            var submitOperation = ViewModel.Context.SubmitChanges(Submited, null);
        }

        public virtual void Submited(SubmitOperation operation)
        {
        }
    }
}
